package com.mxpio.erp.technology.service.impl;

import com.mxpio.erp.common.technology.entity.ProcessInfo;
import com.mxpio.erp.common.technology.entity.ProdTecRout;
import com.mxpio.erp.common.technology.entity.ProdTecRoutProc;
import com.mxpio.erp.common.technology.service.ProdTecRoutProcService;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.system.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author wupaa
 */
@Service
public class ProdTecRoutProcServiceImpl extends BaseServiceImpl<ProdTecRoutProc> implements ProdTecRoutProcService {
    @Override
    @Transactional(readOnly = true)
    public List<ProdTecRoutProc> list(Criteria c) {
        return JpaUtil.linq(ProdTecRoutProc.class).collect("processCode", ProcessInfo.class,"processCode").where(c).list();
    }

    @Override
    @Transactional(readOnly = true)
    public List<ProdTecRoutProc> listByVersion(String routId) {
        ProdTecRout tecRout = JpaUtil.getOne(ProdTecRout.class, routId);
        List<ProdTecRoutProc> lineList = JpaUtil.linq(ProdTecRoutProc.class)
                .collect("processCode", ProcessInfo.class,"processCode")
                .equal("routId", tecRout.getProductItemCode())
                .lessThanOrEqualTo("beginTime", tecRout.getBeginTime())
                .greaterThan("endTime", tecRout.getBeginTime()).list();
        if (lineList.size()>0){
            lineList.forEach(per->per.setSaveTransient(false));
        }
        return lineList;
    }
}
